home *** CD-ROM | disk | FTP | other *** search
/ Aminet 30 / Aminet 30 (1999)(Schatztruhe)[!][Apr 1999].iso / Aminet / dev / misc / IOBlixDevKitR2.lha / IOBlixDevKit / C / examples / QueryParPorts.c < prev    next >
C/C++ Source or Header  |  1999-01-03  |  5KB  |  113 lines

  1. /*
  2.     This program is meant to demonstrate how to get all necessary information
  3.     about a specific chip on an IOBlix board and how to program that chip in a
  4.     system-friendly manner
  5. */
  6.  
  7. #include <exec/exec.h>
  8. #include <resources/ioblix.h>
  9. #include <ioblix/parport.h>
  10. #include <stdio.h>
  11. #include <string.h>
  12.  
  13. #include <proto/exec.h>
  14. #include <proto/ioblix.h>
  15.  
  16.  
  17. UBYTE __aligned myname[]="QueryParPorts 37.1 "__AMIGADATE__;
  18. UBYTE __aligned version[]="$VER: QueryParPorts 37.1 "__AMIGADATE__;
  19. UBYTE __aligned copyright[]="(C)opyright 1998,1999 by Thore Böckelmann and RBM Computertechnik. All rights reserved";
  20.  
  21. struct IOBlixResource *IOBlixBase = NULL;
  22.  
  23. void main(void)
  24. {
  25.     struct IOBlixChipNode *chipNode;
  26.     ULONG board;
  27.     ULONG unit;
  28.     UBYTE *prevOwner;
  29.     struct ParPort *pp;
  30.  
  31.     IOBlixBase = (struct IOBlixResource *)OpenResource(IOBLIXRESNAME);
  32.     if (IOBlixBase) {
  33.         for (board = 0; board < IOBLIX_MAX_Z2_BOARDS; board++) {
  34.             for (unit = 0; unit < IOBLIX_Z2_NUM_PARUNITS; unit++) {
  35.                 /* first simply try to find each parallel port    */
  36.                 /* if it is available then print some information */
  37.                 chipNode = FindChip(ICT_PARALLEL_Z2_CHIP, board*10+unit);
  38.                 if (chipNode) {
  39.                     printf("parallel port %ld on board %ld is a \"%s\" with %ld bytes FIFO\n", unit, board, chipNode->icn_Description, chipNode->icnp_FIFOSize);
  40.                     printf("current user: %s\n", (chipNode->icn_Owner) ? chipNode->icn_Owner : (UBYTE *)"nobody");
  41.                     printf("abilities: ");
  42.                     if (chipNode->icnp_Abilities & PCPAF_SPP) printf("SPP ");
  43.                     if (chipNode->icnp_Abilities & PCPAF_PPF) printf("PPF ");
  44.                     if (chipNode->icnp_Abilities & PCPAF_PS2) printf("PS2 ");
  45.                     if (chipNode->icnp_Abilities & PCPAF_EPP) printf("EPP ");
  46.                     if (chipNode->icnp_Abilities & PCPAF_ECP) printf("ECP ");
  47.                     printf("\n");
  48.  
  49.                     /* now try to obtain chip for exclusive use */
  50.                     prevOwner = NULL;
  51.                     chipNode = ObtainChip(ICT_PARALLEL_Z2_CHIP, board*10+unit, myname, &prevOwner);
  52.                     if (chipNode) {
  53.                         /* for this test we need SPP mode and the ability to switch to other modes with */
  54.                         /* the ECR register */
  55.                         if ((chipNode->icnp_Abilities & (PCPAF_SPP | PCPAF_ECR)) == (PCPAF_SPP | PCPAF_ECR)) {
  56.                             UBYTE oecr;
  57.                             UBYTE testString[] = "The quick brown fox jumps over the lazy dog";
  58.                             UBYTE readBack[256];
  59.                             ULONG cnt, writeCnt;
  60.  
  61.                             pp = (struct ParPort *)chipNode->icn_Address;
  62.                             /* now play a bit with the parport's test mode */
  63.                             /* every value written to the FIFO should also be read back */
  64.                             /* else something really bad has happened */
  65.  
  66.                             oecr = pp->econtrol;
  67.                             /* first set port in SPP mode, else TST mode cannot be activated */
  68.                             /* turn off parport interrupts */
  69.                             pp->econtrol = PARPORT_ECONTROL_SPP | PARPORT_ECONTROL_INT;
  70.                             pp->econtrol = PARPORT_ECONTROL_TST | PARPORT_ECONTROL_INT;
  71.  
  72.                             /* write some data to the FIFO */
  73.                             cnt = 0;
  74.                             do {
  75.                                 pp->tfifo = testString[cnt];
  76.                                 cnt++;
  77.                             } while ((testString[cnt]) && !(pp->econtrol & PARPORT_ECONTROL_FIFO_F));
  78.                             writeCnt = cnt;
  79.                             printf("wrote %ld bytes of \"%s\" to FIFO\n", writeCnt, testString);
  80.  
  81.                             /* and now read the data back */
  82.                             cnt = 0;
  83.                             do {
  84.                                 readBack[cnt] = pp->tfifo;
  85.                                 cnt++;
  86.                             } while ((cnt < writeCnt));
  87.                             readBack[cnt] = 0x00;
  88.                             printf("read %ld bytes from FIFO. \"%s\"\n", cnt, readBack);
  89.  
  90.                             /* restore old econtrol contents */
  91.                             pp->econtrol = PARPORT_ECONTROL_SPP | PARPORT_ECONTROL_INT;
  92.                             pp->econtrol = oecr;
  93.                         } else {
  94.                             printf("parallel port doesn't support anything else than SPP!\n");
  95.                         }
  96.  
  97.                         /* now release the chip again */
  98.                         ReleaseChip(chipNode);
  99.                     } else {
  100.                         /* ObtainChip() failed, so let's check for other owners */
  101.                         if (prevOwner) printf("chip is already in use by \"%s\"\n", prevOwner);
  102.                     }
  103.                 } else {
  104.                     printf("Parallel port %ld on board %ld is not available\n", unit, board);
  105.                 }
  106.             }
  107.         }
  108.     } else {
  109.         printf("Can't find ioblix.resource. Please run SetupIOBlix\n");
  110.     }
  111. }
  112.  
  113.